package com.ruipengkj.view.memberView;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

import com.ruipengkj.bean.TSerShiftType;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.component.JLabelJTextFieldComponent;
import com.ruipengkj.component.RPJButtonBlue;
import com.ruipengkj.component.RPJButtonGray;
import com.ruipengkj.service.TSerShiftTypeService;
import com.ruipengkj.view.base.BaseDialog;

public class SerShiftTypeUpdate extends BaseDialog {
	private static final long serialVersionUID = 1L;
	private JButton okButton;//确定
	private JButton cancel;//取消
	private JLabelJTextFieldComponent messageID = null;//轮牌编号
	private JLabelJTextFieldComponent title = null;//轮牌标题
	private TSerShiftType tSerShiftTypeDialog;
	public boolean isSuccess=false;  //判断是否成功
	
	private TSerShiftTypeService tSerShiftTypeService=BuildSpringApplication.getInstance().getTSerShiftTypeServiceImpl();
	
	public SerShiftTypeUpdate(JDialog jd, String title, boolean b) {
		
		super(jd,title,b);
		this.init();
		this.setSize(300, 550);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
	}
	private void init(){
		this.initViews();
		this.initListener();
		//this.getElements();
	}
	private void initListener(){
		okButton.addActionListener(this);
		cancel.addActionListener(this);
		okButton.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		TSerShiftType tSerShiftType= new TSerShiftType();
		tSerShiftType.setTypeID(messageID.getText().getText().trim());
		String titles=title.getText().getText().trim(); 
		
			if(e.getSource()==okButton){
				if(titles.equals("")){
					JOptionPane.showMessageDialog(null, "轮牌名称不能为空！");
					title.getText().requestFocus();
					return;
				}
				//确定
				try {
					tSerShiftType.setName(titles);
					tSerShiftTypeService.saveOrUpdateService(tSerShiftType);
					isSuccess=true;
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					isSuccess=false;
					e1.printStackTrace();
				}

				this.dispose();
			}else if(e.getSource() ==cancel){
				this.dispose();
			}
		
	}
	private void initViews() {
		JPanel main_jp=new JPanel();
		BoxLayout boxLayout=new BoxLayout(main_jp,BoxLayout.Y_AXIS);
		main_jp.setLayout(boxLayout);
		main_jp.setBackground(Util.PANEL_COLOR);
		messageID=new JLabelJTextFieldComponent("轮牌编号：",30);
		title = new JLabelJTextFieldComponent("轮牌标题：", 30);
		messageID.getText().setEditable(false);
		JPanel jp1=new JPanel();
		okButton=new RPJButtonBlue("确定");
		cancel = new RPJButtonGray("取消");
		jp1.add(okButton);
		jp1.add(cancel);
		jp1.setOpaque(false);
		
		main_jp.add(messageID);
		main_jp.add(title);
		main_jp.add(jp1);
		
		this.add(main_jp);
	}
	public void showDialog(){
		this.setVisible(true);
	}
	public void showDialog(TSerShiftType tSerShiftType){
		if(tSerShiftType!=null){
			tSerShiftTypeDialog = tSerShiftType;
			messageID.getText().setText(tSerShiftType.getTypeID());
			title.getText().setText(tSerShiftType.getName());
		}
		this.setVisible(true);
	}
}
